package com.baitengsoft.patentapimonitor.api.controller;



import com.baitengsoft.patentapimonitor.api.entity.SysAdminUserTokenEntity;
import com.baitengsoft.patentapimonitor.api.entity.SysAdmininfoEntity;
import com.baitengsoft.patentapimonitor.api.entity.WebApplicanttypeRlatEntity;
import com.baitengsoft.patentapimonitor.api.service.SysAdminUserTokenService;
import com.baitengsoft.patentapimonitor.api.service.SysAdmininfoService;
import com.baitengsoft.patentapimonitor.api.service.WebUserTokenService;
import com.baitengsoft.patentapimonitor.api.service.WebApplicanttypeRlatService;
import com.baitengsoft.patentapimonitor.common.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * API测试接口
 *index
 * @author KennyGu
 * @date 2017-11-27 15:47
 */
@RestController
@RequestMapping("api/v1/admin")
@Api(value = "后台-用户登录",description = "用户登录")
public class AdminIndexController extends AbstractController {

    @Autowired
    private SysAdmininfoService sysadmininfoservice;

    @Autowired
    private SysAdminUserTokenService sysAdminTokenService;
    /**
     * 获取用户信息
     */
    @ApiOperation(value = "验证用户登录")
    @RequestMapping(value="/login", method= RequestMethod.POST)
    public Res userInfo(@RequestParam("userName") String userName,@RequestParam("passWord") String password){
       // Map userInfoMap=sysadmininfoservice.queryByUserName(userName,password);
        //用户信息
        SysAdmininfoEntity user = sysadmininfoservice.queryByUserName(userName);

        //账号不存在、密码错误
        if(user == null || !user.getPwd().equals(password)) {
            return Res.error("账号或密码不正确");
        }

        //生成token，并保存到数据库
        Res r = sysAdminTokenService.createToken(user.getId());

       return r;
    }

    /**
     * 退出
     */
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public Res logout() {
        sysAdminTokenService.logout(getAdminUserId());
        return Res.ok();
    }

    @ApiOperation(value = "测试")
    @RequestMapping(value="/test", method= RequestMethod.GET)
    public Res test(@RequestParam("id") int id){
 getAdminUserId();
        return Res.ok();
    }


}
